package com.qyhl.webtv.module_news.news.union.government.detail;

import android.Manifest;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.appbar.CollapsingToolbarLayout;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestOptions;
import com.gyf.immersionbar.ImmersionBar;
import com.qinanyu.bannerview.holder.SimpleHolder;
import com.qinanyu.bannerview.view.SimpleBannerView;
import com.qyhl.cloud.webtv.module_news.R;
import com.qyhl.cloud.webtv.module_news.R2;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.basiclib.utils.MPermissionUtils;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.basiclib.utils.glide.GlideRoundTransform;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.qyhl.webtv.commonlib.entity.news.MeetingRoomBean;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.commonlib.entity.news.UnionBean;
import com.qyhl.webtv.commonlib.entity.news.UnionRecBean;
import com.qyhl.webtv.commonlib.item.ItemAdvCommon;
import com.qyhl.webtv.commonlib.item.ItemAdvGroup;
import com.qyhl.webtv.commonlib.item.ItemAdvLarge;
import com.qyhl.webtv.commonlib.item.ItemCatchNews;
import com.qyhl.webtv.commonlib.item.ItemCommonLarge;
import com.qyhl.webtv.commonlib.item.ItemCommonLeft;
import com.qyhl.webtv.commonlib.item.ItemCommonRight;
import com.qyhl.webtv.commonlib.item.ItemCommonThreePics;
import com.qyhl.webtv.commonlib.item.ItemGoodLife;
import com.qyhl.webtv.commonlib.item.ItemNoPicture;
import com.qyhl.webtv.commonlib.item.ItemPicture;
import com.qyhl.webtv.commonlib.item.ItemSmallVideo;
import com.qyhl.webtv.commonlib.item.ItemTitleNews;
import com.qyhl.webtv.commonlib.item.ItemTopNews;
import com.qyhl.webtv.commonlib.item.ItemTopNoPicture;
import com.qyhl.webtv.commonlib.item.ItemUnion;
import com.qyhl.webtv.commonlib.item.ItemUnionTag;
import com.qyhl.webtv.commonlib.item.ItemVideoLarge;
import com.qyhl.webtv.commonlib.item.ItemVideoLeft;
import com.qyhl.webtv.commonlib.item.ItemVideoRight;
import com.qyhl.webtv.commonlib.utils.ItemSkipUtils;
import com.qyhl.webtv.commonlib.utils.MShareBoard;
import com.qyhl.webtv.commonlib.utils.router.RouterManager;
import com.qyhl.webtv.module_news.news.union.town.detail.TownDetailContract;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.UMShareAPI;
import com.weavey.loading.lib.LoadingLayout;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by qyhl on 2017/12/1.
 */

@Route(path = ARouterPathConstant.DETAIL_GOV)
public class GovernmentDetailActivity extends BaseActivity implements TownDetailContract.TownDetailView {
    @BindView(R2.id.title)
    TextView title;
    @BindView(R2.id.banner)
    SimpleBannerView banner;
    @BindView(R2.id.collapsing_layout)
    CollapsingToolbarLayout collapsingLayout;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.listView)
    RecyclerView listView;
    @BindView(R2.id.refresh)
    SmartRefreshLayout refresh;
    @BindView(R2.id.load_mask)
    LoadingLayout loadMask;
    @BindView(R2.id.back)
    ImageView back;
    @BindView(R2.id.share_btn)
    ImageView shareBtn;
    @BindView(R2.id.to_meetingRoom)
    RelativeLayout toMeetingRoom;
    @BindView(R2.id.meeting_name)
    TextView meetingName;

    private GovernmentDetailPresenter mPresenter;

    @Autowired(name = "id")
    String sectionId;

    @Autowired(name = "title")
    String mTitle;

    @Autowired(name = "cover")
    String cover;

    private String mSections = "";

    private com.zhy.adapter.recyclerview.MultiItemTypeAdapter mAdapter;

    private CommonAdapter<UnionBean> commonAdapter;

    private RequestOptions options;

    private List<UnionBean> middleList;
    private List<NewsBean> topList;
    private List<UnionRecBean> bottomList;
    private List<GlobalNewsBean> mDataList;
    private List<GlobalNewsBean> indexList;

    private float mFirstY;//用户首次触摸的Y坐标
    private float mLastY;//用户滑动结束时Y坐标
    private float mTouchSlop = 5.0f;

    private int streetId;
    private String titleName;
    private boolean hasRoom;
    private int rule;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.WHITE);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

    }

    @Override
    protected int getContentView() {
        return R.layout.news_activity_union_detail_gov;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {

    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        mPresenter = new GovernmentDetailPresenter(this);
        initView();

    }

    @Override
    protected void setListener() {
        setListeners();
        mPresenter.getMiddle(sectionId);
        mPresenter.getMeetingRoom(sectionId);
    }

    /**
     * 初始化
     */
    private void initView() {
        loadMask.setStatus(LoadingLayout.Loading);

        title.setText(mTitle);

        middleList = new ArrayList<>();
        topList = new ArrayList<>();
        bottomList = new ArrayList<>();
        mDataList = new ArrayList<>();

        options = new RequestOptions()
                .centerCrop()
                .placeholder(R.drawable.cover_normal_default)
                .error(R.drawable.cover_normal_default)
                .priority(Priority.HIGH)
                .optionalTransform(new GlideRoundTransform(4));

        //刷新控件
        refresh.setRefreshHeader(new MaterialHeader(this));
        refresh.setDisableContentWhenRefresh(true);
        refresh.setEnableLoadMore(false);

        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        commonAdapter = new CommonAdapter<UnionBean>(this, R.layout.news_item_union_middle, middleList) {

            @Override
            protected void convert(ViewHolder holder, UnionBean townBean, int position) {
                TextView txt = holder.getView(R.id.title);
                txt.setText(townBean.getName());
            }
        };
        recyclerView.setAdapter(commonAdapter);


        //设置布局管理器
        LinearLayoutManager linearLayoutManager2 = new LinearLayoutManager(this);
        linearLayoutManager2.setOrientation(LinearLayoutManager.VERTICAL);
        listView.setLayoutManager(linearLayoutManager2);

        listView.addItemDecoration(new com.luck.picture.lib.decoration.RecycleViewDivider(
                this, LinearLayoutManager.HORIZONTAL, 1, ContextCompat.getColor(this, R.color.global_gray_lv3)));
        //初始化适配器
        mAdapter = new com.zhy.adapter.recyclerview.MultiItemTypeAdapter(this, mDataList);
        mAdapter.addItemViewDelegate(new ItemAdvCommon(this));
        mAdapter.addItemViewDelegate(new ItemAdvGroup(this));
        mAdapter.addItemViewDelegate(new ItemAdvLarge(this));
        mAdapter.addItemViewDelegate(new ItemCatchNews(this));
        mAdapter.addItemViewDelegate(new ItemCommonLarge(this));
        mAdapter.addItemViewDelegate(new ItemCommonRight(this));
        mAdapter.addItemViewDelegate(new ItemCommonLeft(this));
        mAdapter.addItemViewDelegate(new ItemGoodLife(this));
        mAdapter.addItemViewDelegate(new ItemNoPicture(this));
        mAdapter.addItemViewDelegate(new ItemPicture(this));
        mAdapter.addItemViewDelegate(new ItemTitleNews(this));
        mAdapter.addItemViewDelegate(new ItemTopNews(this));
        mAdapter.addItemViewDelegate(new ItemTopNoPicture(this));
        mAdapter.addItemViewDelegate(new ItemVideoLarge(this));
        mAdapter.addItemViewDelegate(new ItemVideoLeft(this));
        mAdapter.addItemViewDelegate(new ItemVideoRight(this));
        mAdapter.addItemViewDelegate(new ItemSmallVideo(this));
        mAdapter.addItemViewDelegate(new ItemUnion(this));
        mAdapter.addItemViewDelegate(new ItemUnionTag());
        mAdapter.addItemViewDelegate(new ItemCommonThreePics(this));

        listView.setAdapter(mAdapter);

    }

    /**
     * 监听
     */
    private void setListeners() {
        //刷新
        refresh.setOnRefreshListener(refreshlayout -> mPresenter.getMiddle(sectionId));

        //重载
        loadMask.setOnReloadListener(v -> {
            loadMask.setReloadButtonText("加载中...");
            mPresenter.getMiddle(sectionId);
        });

        //轮播点击
        banner.setOnItemClickListener(position -> {
            NewsBean bean = topList.get(position);
            boolean hasPicture = StringUtils.isPictureSuccess(bean.getLogo());
            String type = "", pOne = "", pTwo = "", pThree = "";
            int style = 0;
            switch (bean.getType()) {
                case "1"://普通新闻
                    type = "1";
                    switch (bean.getPluralPicsFlag()) {
                        case 0:
                            style = bean.getCommonStyle();
                            break;
                        case 1://三图
                            hasPicture = false;
                            if (bean.getImagess().size() == 1) {
                                hasPicture = true;
                                pOne = bean.getImagess().get(0).getImageUrlString();
                            } else if (bean.getImagess().size() == 2) {
                                pOne = bean.getImagess().get(0).getImageUrlString();
                                pTwo = bean.getImagess().get(1).getImageUrlString();
                                hasPicture = true;
                            } else if (bean.getImagess().size() >= 3) {
                                pOne = bean.getImagess().get(0).getImageUrlString();
                                pTwo = bean.getImagess().get(1).getImageUrlString();
                                pThree = bean.getImagess().get(2).getImageUrlString();
                                hasPicture = true;
                            } else {
                                hasPicture = false;
                            }
                            style = 4;
                            break;
                        case 2:
                            style = 3;
                            break;
                        default:
                            style = bean.getCommonStyle();
                            break;
                    }
                    break;
                case "2"://图片新闻
                    type = "2";
                    if (bean.getImagess().size() == 1) {
                        pOne = bean.getImagess().get(0).getImageUrlString();
                        hasPicture = true;
                    } else if (bean.getImagess().size() == 2) {
                        pOne = bean.getImagess().get(0).getImageUrlString();
                        pTwo = bean.getImagess().get(1).getImageUrlString();
                        hasPicture = true;
                    } else if (bean.getImagess().size() >= 3) {
                        pOne = bean.getImagess().get(0).getImageUrlString();
                        pTwo = bean.getImagess().get(1).getImageUrlString();
                        pThree = bean.getImagess().get(2).getImageUrlString();
                        hasPicture = true;
                    } else {
                        hasPicture = false;
                    }
                    break;
                case "3"://直播
                    type = "9";
                    break;
                case "4"://标题新闻
                    type = "8";
                    break;
                case "5"://视频新闻
                    type = "3";
                    style = bean.getVideoStyle();
                    break;
                case "8"://互动直播
                    bean.setID(bean.getRoomId());//将roomId设置成通用Id
                    type = "5";
                    break;
                case "101"://抓取新闻
                    type = "10";
                    break;
                default:
                    break;
            }
            GlobalNewsBean globalNewsBean = new GlobalNewsBean(bean.getTitle(), bean.getID(), bean.getRedirectURL(), bean.getLogo(), style, bean.getPublishDate(), type, Integer.parseInt(bean.getHitCount()), bean.getSource(), bean.getCatalogID(), hasPicture, pOne, pTwo, pThree, bean.getLivetype());
            ItemSkipUtils.getInstance().itemSkip(globalNewsBean, GovernmentDetailActivity.this);
        });

        //栏目点击
        commonAdapter.setOnItemClickListener(new com.zhy.adapter.recyclerview.MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("id", middleList.get(position).getId());
                bundle.putString("title", middleList.get(position).getName());
                RouterManager.router(ARouterPathConstant.NEWS_LIST, bundle);

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        //返回监听
        back.setOnClickListener(v -> finish());

        //分享
        shareBtn.setOnClickListener(v -> MPermissionUtils.requestPermissionsResult(GovernmentDetailActivity.this, 1, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, new MPermissionUtils.OnPermissionListener() {
            @Override
            public void onPermissionGranted() {
                MShareBoard shareBoard = new MShareBoard(GovernmentDetailActivity.this, sectionId, mTitle, cover, "", CommonUtils.getInstance().getBannerId(), 10);
                shareBoard.showPopupWindow();
            }

            @Override
            public void onPermissionDenied() {
                MPermissionUtils.showTipsDialog(GovernmentDetailActivity.this);
            }
        }));
        mAdapter.setOnItemClickListener(new com.zhy.adapter.recyclerview.MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                GlobalNewsBean bean = mDataList.get(position);
                ItemSkipUtils.getInstance().itemSkip(bean, GovernmentDetailActivity.this);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });


        listView.setOnTouchListener((v, event) -> {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mFirstY = event.getY();//getY获取的是相对于View的坐标，getRawY获取的是相对于屏幕的坐标
                    break;
                case MotionEvent.ACTION_MOVE:
                    mLastY = event.getY();
                    if (mLastY - mFirstY > mTouchSlop) {//手指向下滑动
                        if (toMeetingRoom.getVisibility() == View.GONE) {
                            if (hasRoom) {
                                endAnima(toMeetingRoom);
                            }
                        }
                    } else if (mFirstY - mLastY > mTouchSlop) {//手指向上滑动
                        if (toMeetingRoom.getVisibility() == View.VISIBLE) {
                            if (hasRoom) {
                                startAnima(toMeetingRoom);
                            }
                        }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                default:
                    break;
            }
            return false;
        });


        toMeetingRoom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("id", streetId + "");
                bundle.putString("title", titleName);
                bundle.putString("rule", rule + "");
                RouterManager.router(ARouterPathConstant.MEETING_ROOM, bundle);

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    private void startAnima(final View view) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "translationY", 0f, 200f);
//      设置移动时间
        objectAnimator.setDuration(300);

        objectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
//      开始动画
        objectAnimator.start();


    }

    private void endAnima(final View view) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "translationY", 200f, 0f);
//      设置移动时间
        objectAnimator.setDuration(300);
        objectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
//      开始动画
        objectAnimator.start();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        MPermissionUtils.onRequestPermissionsResult(requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    /**
     * 设置栏目列表
     *
     * @param beanList
     */
    @Override
    public void setMiddle(List<UnionBean> beanList) {
        middleList.clear();
        middleList.addAll(beanList);

        mSections = "";
        for (int i = 0; i < middleList.size(); i++) {
            if (i == (middleList.size() - 1)) {
                mSections = mSections + middleList.get(i).getId();
            } else {
                mSections = mSections + middleList.get(i).getId() + ",";
            }
        }
        mPresenter.getTop(mSections);
    }

    /**
     * 出错
     *
     * @param msg
     */
    @Override
    public void setError(String msg) {
        refresh.finishRefresh();
        loadMask.setErrorText(msg);
        loadMask.setStatus(LoadingLayout.Error);
        loadMask.setReloadButtonText("点击重试~~");
    }

    /**
     * 无内容
     *
     * @param msg
     */
    @Override
    public void setEmpty(String msg) {
        refresh.finishRefresh();
        loadMask.setEmptyText(msg);
        loadMask.setStatus(LoadingLayout.Empty);
        loadMask.setReloadButtonText("点击重试~~");
    }

    /**
     * 无网络
     *
     * @param msg
     */
    @Override
    public void setNetError(String msg) {
        refresh.finishRefresh();
        loadMask.setNoNetworkText(msg);
        loadMask.setStatus(LoadingLayout.No_Network);
        loadMask.setReloadButtonText("点击重试~~");
    }

    /**
     * 设置轮播
     *
     * @param beanList
     */
    @Override
    public void setTop(List<NewsBean> beanList) {
        topList.clear();
        topList.addAll(beanList);

        if (beanList != null && beanList.size() > 0) {
            banner.setVisibility(View.VISIBLE);
            collapsingLayout.setVisibility(View.VISIBLE);
        } else {
            banner.setVisibility(View.GONE);
            collapsingLayout.setVisibility(View.GONE);
        }


        List<String> titleNames = new ArrayList<>();
        for (int i = 0; i < topList.size(); i++) {
            titleNames.add(topList.get(i).getTitle());
        }
        String[] titleStrings = new String[titleNames.size()];
        titleNames.toArray(titleStrings);
        if (titleStrings.length == 1) {
            banner.setCanLoop(false);
            banner.setTextBanner(titleStrings[0]);
        }
        banner.setPages(() -> new BannerImageHolderView(), topList)
                .startTurning(3000)
                .setPageIndicator(new int[]{R.drawable.news_banner_indicator_off, R.drawable.news_banner_indicator_on}, titleStrings)
                .setPageIndicatorAlign(SimpleBannerView.PageIndicatorAlign.ALIGN_PARENT_RIGHT);

        mPresenter.getBottom(mSections);
    }

    /**
     * 无轮播
     *
     * @param msg
     */
    @Override
    public void setTopError(String msg) {
        banner.setVisibility(View.GONE);
        collapsingLayout.setVisibility(View.GONE);
        Log.i("detail_town", msg);
        mPresenter.getBottom(mSections);
    }

    /**
     * 设置推荐内容
     *
     * @param beanList
     */
    @Override
    public void setBottom(List<UnionRecBean> beanList) {
        refresh.finishRefresh();
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~~");

        bottomList.clear();
        bottomList.addAll(beanList);

        indexList = new ArrayList<>();
        for (int i = 0; i < bottomList.size(); i++) {
            indexList.add(new GlobalNewsBean(bottomList.get(i).getCatalogName(), "", "", "", 0, "", "100", 0, "", bottomList.get(i).getCatalogId(), true, null));
            if (bottomList.get(i).getNews() != null && bottomList.get(i).getNews().size() > 0) {
                for (int j = 0; j < bottomList.get(i).getNews().size(); j++) {
                    NewsBean bean = bottomList.get(i).getNews().get(j);
                    boolean hasPicture = StringUtils.isPictureSuccess(bean.getLogo());
                    String type = "", pOne = "", pTwo = "", pThree = "";
                    int style = 0;
                    switch (bean.getType()) {
                        case "1"://普通新闻
                            type = "1";
                            switch (bean.getPluralPicsFlag()) {
                                case 0:
                                    style = Integer.parseInt(CommonUtils.getInstance().getGlobalCommon());
                                    break;
                                case 1://三图
                                    hasPicture = false;
                                    if (bean.getImagess().size() == 1) {
                                        hasPicture = true;
                                        pOne = bean.getImagess().get(0).getImageUrlString();
                                    } else if (bean.getImagess().size() == 2) {
                                        pOne = bean.getImagess().get(0).getImageUrlString();
                                        pTwo = bean.getImagess().get(1).getImageUrlString();
                                        hasPicture = true;
                                    } else if (bean.getImagess().size() >= 3) {
                                        pOne = bean.getImagess().get(0).getImageUrlString();
                                        pTwo = bean.getImagess().get(1).getImageUrlString();
                                        pThree = bean.getImagess().get(2).getImageUrlString();
                                        hasPicture = true;
                                    } else {
                                        hasPicture = false;
                                    }
                                    style = 4;
                                    break;
                                case 2:
                                    style = 3;
                                    break;
                                default:
                                    style = Integer.parseInt(CommonUtils.getInstance().getGlobalCommon());
                                    break;
                            }
                            break;
                        case "2"://图片新闻
                            type = "2";
                            if (bean.getImagess().size() == 1) {
                                pOne = bean.getImagess().get(0).getImageUrlString();
                                hasPicture = true;
                            } else if (bean.getImagess().size() == 2) {
                                pOne = bean.getImagess().get(0).getImageUrlString();
                                pTwo = bean.getImagess().get(1).getImageUrlString();
                                hasPicture = true;
                            } else if (bean.getImagess().size() >= 3) {
                                pOne = bean.getImagess().get(0).getImageUrlString();
                                pTwo = bean.getImagess().get(1).getImageUrlString();
                                pThree = bean.getImagess().get(2).getImageUrlString();
                                hasPicture = true;
                            } else {
                                hasPicture = false;
                            }
                            break;
                        case "3"://直播
                            type = "9";
                            break;
                        case "4"://标题新闻
                            type = "8";
                            break;
                        case "5"://视频新闻
                            type = "3";
                            style = Integer.parseInt(CommonUtils.getInstance().getGlobalVideo());
                            break;
                        case "8"://互动直播
                            bean.setID(bean.getRoomId());//将roomId设置成通用Id
                            type = "5";
                            break;
                        case "101"://抓取新闻
                            type = "10";
                            break;
                        default:
                            break;
                    }
                    indexList.add(new GlobalNewsBean(bean.getTitle(), bean.getID(), bean.getRedirectURL(), bean.getLogo(), style, bean.getPublishDate(), type, Integer.parseInt(bean.getHitCount()), bean.getSource(), bean.getCatalogID(), hasPicture, pOne, pTwo, pThree, bean.getLivetype(), bean.getCommentCount()));
                }
            }

        }

        mDataList.clear();
        mDataList.addAll(indexList);
        mAdapter.notifyDataSetChanged();

    }

    /**
     * 无推荐内容
     *
     * @param msg
     */
    @Override
    public void setBottomError(int code, String msg) {
        refresh.finishRefresh();
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~~");
        if (code == 1) {
            Log.i("detail_town", msg);
        } else {
            mDataList.clear();
            mAdapter.notifyDataSetChanged();
        }
    }

    /**
     * 成功获取议事厅
     *
     * @param bean
     */
    @Override
    public void getMeetingSuccess(MeetingRoomBean bean) {
        hasRoom = true;
        toMeetingRoom.setVisibility(View.VISIBLE);
        streetId = bean.getId();
        titleName = bean.getMeetingName();
        rule = bean.getMessageRule();
        meetingName.setText(titleName);
    }

    /**
     * 无议事厅
     */
    @Override
    public void getMeetingError() {
        hasRoom = false;
        toMeetingRoom.setVisibility(View.GONE);
    }

    class BannerImageHolderView implements SimpleHolder<NewsBean> {
        private ImageView imageView;

        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, NewsBean data) {
            Glide.with(context.getApplicationContext())
                    .load(data.getLogo())
                    .apply(options)
                    .into(imageView);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        //baidu
        //umeng
        MobclickAgent.onPageStart("政务详情");
        MobclickAgent.onResume(this);
    }


    @Override
    protected void onPause() {
        super.onPause();
        //baidu
        //umeng
        MobclickAgent.onPageEnd("政务详情");
        MobclickAgent.onPause(this);
    }
}
